package com.uls.web.controller.czj;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uls.czj.domain.CzjLand;
import com.uls.hdh.domain.HdhUsers;
import com.uls.hdh.service.IHdhUsersService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.czj.domain.CzjHousingsubsidy;
import com.uls.czj.service.ICzjHousingsubsidyService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 住房补贴管理Controller
 * 
 * @author czj
 * @date 2024-11-10
 */
@RestController
@RequestMapping("/czj/housingsubsidy")
public class CzjHousingsubsidyController extends BaseController
{
    @Autowired
    private ICzjHousingsubsidyService czjHousingsubsidyService;


    @Autowired
    private IHdhUsersService hdhUsersService;
    /**
     * 查询住房补贴管理列表
     */
    @PreAuthorize("@ss.hasPermi('czj:housingsubsidy:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzjHousingsubsidy czjHousingsubsidy)
    {
        startPage();
        List<CzjHousingsubsidy> list = czjHousingsubsidyService.selectCzjHousingsubsidyList(czjHousingsubsidy);

        //List<CzjHousingsubsidy> list1 = new ArrayList<>();
        for (CzjHousingsubsidy czjHousingsubsidy1:list){
            HdhUsers hdhUsers = hdhUsersService.selectHdhUsersByUsersId(czjHousingsubsidy1.getPersonnelid());
            czjHousingsubsidy1.setPersonnelname(hdhUsers.getUsername());
            //list1.add(czjHousingsubsidy1);
        }
        return getDataTable(list);
    }

    /**
     * 导出住房补贴管理列表
     */
    @PreAuthorize("@ss.hasPermi('czj:housingsubsidy:export')")
    @Log(title = "住房补贴管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzjHousingsubsidy czjHousingsubsidy)
    {
        List<CzjHousingsubsidy> list = czjHousingsubsidyService.selectCzjHousingsubsidyList(czjHousingsubsidy);
        ExcelUtil<CzjHousingsubsidy> util = new ExcelUtil<CzjHousingsubsidy>(CzjHousingsubsidy.class);
        util.exportExcel(response, list, "住房补贴管理数据");
    }

    /**
     * 获取住房补贴管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('czj:housingsubsidy:query')")
    @GetMapping(value = "/{subsidyid}")
    public AjaxResult getInfo(@PathVariable("subsidyid") Long subsidyid)
    {
        return success(czjHousingsubsidyService.selectCzjHousingsubsidyBySubsidyid(subsidyid));
    }

    /**
     * 新增住房补贴管理
     */
    @PreAuthorize("@ss.hasPermi('czj:housingsubsidy:add')")
    @Log(title = "住房补贴管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzjHousingsubsidy czjHousingsubsidy)
    {
        return toAjax(czjHousingsubsidyService.insertCzjHousingsubsidy(czjHousingsubsidy));
    }

    /**
     * 修改住房补贴管理
     */
    @PreAuthorize("@ss.hasPermi('czj:housingsubsidy:edit')")
    @Log(title = "住房补贴管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzjHousingsubsidy czjHousingsubsidy)
    {
        return toAjax(czjHousingsubsidyService.updateCzjHousingsubsidy(czjHousingsubsidy));
    }

    /**
     * 删除住房补贴管理
     */
    @PreAuthorize("@ss.hasPermi('czj:housingsubsidy:remove')")
    @Log(title = "住房补贴管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subsidyids}")
    public AjaxResult remove(@PathVariable Long[] subsidyids)
    {
        return toAjax(czjHousingsubsidyService.deleteCzjHousingsubsidyBySubsidyids(subsidyids));
    }

    @PreAuthorize("@ss.hasPermi('czj:housingsubsidy:submitStudent')")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/submitSubsidy")
    public  AjaxResult  submitStudent(@RequestBody Long subsidyid){
        return toAjax(czjHousingsubsidyService.submit(subsidyid,getUserId()));
    }

    /**
     * 查询未审批的学生信息列表
     */
    @PreAuthorize("@ss.hasPermi('edu:student:editnoapprove')")
    @Log(title = "查询未审批的学生信息列表", businessType = BusinessType.EXPORT)
    @PostMapping("/editnoapprove")
    public AjaxResult editSaveNoAuthData(@RequestBody CzjHousingsubsidy czjHousingsubsidy)
    {
        czjHousingsubsidyService.completeTask(czjHousingsubsidy.getFlowInstantId(),czjHousingsubsidy.getAgree(),getUserId(),czjHousingsubsidy.getComment(),czjHousingsubsidy.getSubsidyid());
        return  toAjax(200);
    }


    @PreAuthorize("@ss.hasPermi('edu:student:listNo')")
    @GetMapping("/listNo")
    public TableDataInfo listNo(CzjHousingsubsidy czjHousingsubsidy) {

        startPage();
        // List<SysStudent> list = sysStudentService.noFinishTask(getUserId(),"myStudentProcess");//关联工作流没有带条件查询
        List<CzjHousingsubsidy> list = czjHousingsubsidyService.noFinishTask(getUserId(),"czjWord",czjHousingsubsidy);//关联工作流带条件查询
        return getDataTable(list);

    }


    /**
     * 获取学生信息详细信息
     */
    @GetMapping(value = "/getStudentComment/{studentId}")
    public AjaxResult getInfoComment(@PathVariable("studentId") Long subsidyid)
    {
        CzjHousingsubsidy czjHousingsubsidy=czjHousingsubsidyService.selectCzjHousingsubsidyBySubsidyid(subsidyid);

        czjHousingsubsidy.setTaskCommentVoList(czjHousingsubsidyService.getTaskCommentList(czjHousingsubsidy.getFlowInstantId()));  //找出前面审批人的审批信息

        System.out.println(czjHousingsubsidy.getTaskCommentVoList());
        return success(czjHousingsubsidy);
    }


    @PreAuthorize("@ss.hasPermi('edu:student:listFinished')")
    @PostMapping("/listFinished")
    public TableDataInfo listFinished(@RequestBody CzjHousingsubsidy czjHousingsubsidy)
    {
        startPage();
        System.out.println(czjHousingsubsidy.toString());
        List<CzjHousingsubsidy> list = czjHousingsubsidyService.finishTask(getUserId(),"czjWord",czjHousingsubsidy);//关联工作流带条件查询
        return getDataTable(list);
    }
}
